﻿using EasyCaching.Core;
using Library.Common.Serialize;
using Library.Core.Application.BaseAction;
using Library.Core.Application.IInfrastructure;
using Synthesize.Common.Domain.Aggregation.Dtos;
using Synthesize.Common.ServiceInterface.Query;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Synthesize.Common.Application.Query
{
    /// <summary>
    /// 接口安全查询逻辑
    /// </summary>
    public class SafeQueryService : BaseService, ISafeQueryService
    {
        private readonly IRedisCachingProvider _redisCaching;


        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="container"></param>
        /// <param name="redisCaching"></param>
        public SafeQueryService(IIocContainer container
            , IRedisCachingProvider redisCaching
            ) : base(container)
        {
            _redisCaching = redisCaching;
        }

        /// <summary>
        /// 获取所有名单信息
        /// </summary>
        /// <returns></returns>
        public async Task<List<ApiMonitorNameListOutput>> GetMonitorLogList()
        {
            var result = new List<ApiMonitorNameListOutput>();
            var monitorNameList = await _redisCaching.HGetAllAsync(RedisLogInfo.RedisApiMonitorNameListHashId);
            if (monitorNameList != null)
            {
                result = JsonHelper.JsonToObject<List<ApiMonitorNameListOutput>>(JsonHelper.ToJson(monitorNameList));
            }
            return result;
        }
    }
}
